// Growth rate calculator.
// Algorithms for calculating maximal eigenvalue of adjacency matrix of
// a given DFA using efficient numerical methods.

#ifndef GRATE_EIGENVALUE_H
#define GRATE_EIGENVALUE_H

#include "grate/util/common.h"

namespace growth_rate {

class DFAInterface;

struct EigenvalueOptions {
  // Fills in default values.
  EigenvalueOptions();

  enum FindSccStrategy {
    FindSccNever,  // never find scc in a DFA (requires oracle usage).
    FindSccDefault,  // use naive algorithm for finding SCC.
    FindSccAssumeSingle,  // use optimized algorithm, which assumes there is
                          // a single scc in a DFA).
    FindSccCnt
  } scc_strategy;
  double precision;
  size_t max_iterations;
  bool add_loops_to_nodes;
  bool use_oracle;
  bool verbosity;
  enum GenerateEdgeListMode {
    EdgeListModeAlways,
    EdgeListModeNever,
    EdgeListModeAuto,
    EdgeListModeCnt
  } generate_edge_list_mode;
};

class EigenvalueCalculator {
 public:
  // Returns the maximal eigenvalue of DFA adjacency matrix.
  // NOTE: this call deletes the DFA!
  static double get_max_eigenvalue(
      DFAInterface *dfa,
      const EigenvalueOptions &options = EigenvalueOptions(),
      size_t *iterations_used = 0);
};

}  // namespace growth_rate

#endif  // GRATE_EIGENVALUE_H
